package com.iflytek.jcy.supervise.clue.web;

import com.alibaba.fastjson.JSON;
import com.iflytek.jcy.supervise.clue.component.httpinterface.ModelHttpInterface;
import com.iflytek.jcy.supervise.clue.component.httpinterface.param.OuterZbajParam;
import com.iflytek.jcy.supervise.clue.component.httpinterface.result.*;
import com.iflytek.jcy.supervise.clue.dto.*;
import com.iflytek.jcy.supervise.clue.dto.inquisitor.ManageDTO;

import com.iflytek.jcy.supervise.clue.service.*;
import com.iflytek.jcy.supervise.clue.web.vo.UapUserInfoVo;

import cn.dev33.satoken.stp.StpUtil;

import org.springframework.web.bind.annotation.*;

import com.alibaba.fastjson.JSONObject;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.iflytek.jcy.supervise.clue.common.constants.AppConstants;
import com.iflytek.jcy.supervise.clue.common.enums.ResultEnum;
import com.iflytek.jcy.supervise.clue.common.pojo.CommonResponse;
import com.iflytek.jcy.supervise.clue.common.pojo.MongoPageResult;
import com.iflytek.jcy.supervise.clue.component.converter.BeanConverter;
import com.iflytek.jcy.supervise.clue.component.httpinterface.SjztHttpInterface;
import com.iflytek.jcy.supervise.clue.component.httpinterface.param.ClueUser;
import com.iflytek.jcy.supervise.clue.dto.response.ClueCollectionDTO;
import com.iflytek.jcy.supervise.clue.dto.response.DepartmentVO;
import com.iflytek.jcy.supervise.clue.dto.response.ManageTaskDetailDTO;

import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;

import java.util.ArrayList;
import java.util.Collection;
import java.util.Comparator;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.Set;
import java.util.stream.Collectors;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.apache.commons.collections4.CollectionUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.validation.annotation.Validated;

/**
 * <p>
 * 线索 前端控制器
 * </p>
 *
 * @author dgyu
 * @since 2022-10-20 */
@RequestMapping("/clue")
@Api(value = "线索接口", tags = { "线索接口" })
@RestController
public class ClueController {

	private static final Logger		  logger = LoggerFactory.getLogger(ClueController.class);

	@Autowired
	private IClueService			  iClueService;
	@Autowired
	private IClueCollectionService	  iClueCollectionService;
	@Autowired
	private IClueCollectionMapService iClueCollectionMapService;
	@Autowired
	private ITaskDetailService		  iTaskDetailService;
	@Resource
	private SjztHttpInterface		  sjztHttpInterface;
	@Autowired
	private BeanConverter			  converter;
	@Autowired
	private ICluePushService		  iCluePushService;
	@Autowired
	private ICluePushDetailService	  iCluePushDetailService;
	@Resource
	private ModelHttpInterface		  modelHttpInterface;
	@Resource
	private MongoService			  mongoService;
	@Value("${sjzt.dwbm}")
	private String					  sjztDwbm;
	@Resource
	private ClueUser			clueUser;

	@PostMapping("/list")
	@ApiOperation(value = "线索管理分页查询(管理员)", notes = "线索管理分页查询(管理员)")
	public CommonResponse list(@RequestBody QueryClueDTO queryClueDTO) {
		return CommonResponse.success(this.iClueService.list(queryClueDTO));
	}

	@PostMapping("/list/result")
	@ApiOperation(value = "线索结果列表分页查询(管理员)", notes = "线索结果列表分页查询(管理员)")
	public CommonResponse listResult(@RequestBody QueryClueResultDTO queryClueResultDTO) {
		return CommonResponse.success(this.iTaskDetailService.listResult(queryClueResultDTO));
	}

	@PostMapping("/setWeight/{id}/{weight}")
	@ApiOperation(value = "线索结果列表-设置权重", notes = "线索结果列表-设置权重")
	public CommonResponse setWeight(@PathVariable(required = true, name = "id") Integer id, @PathVariable(required = true, name = "weight") Integer weight) {
		int rows = this.iTaskDetailService.setWeight(id, weight);
		return rows > 0 ? CommonResponse.success() : CommonResponse.failed(ResultEnum.CLUE_RESULT_SET_WEIGHT_ERROR);
	}

	@DeleteMapping("/{id}")
	@ApiOperation(value = "线索结果列表-删除线索", notes = "线索结果列表-删除线索结果")
	public CommonResponse getCollections(@PathVariable(required = true, name = "id") Integer id) {
		int rows = this.iTaskDetailService.deleteById(id);
		return rows > 0 ? CommonResponse.success() : CommonResponse.failed(ResultEnum.CLUE_RESULT_DELETE_ERROR);
	}

	@GetMapping("/{id}/{rybm}")
	@ApiOperation(value = "线索结果列表-加入线索集-查询线索集", notes = "线索结果列表-加入线索集-查询线索集")
	public CommonResponse queryCollections(@PathVariable(required = true, name = "id") Integer id, @PathVariable(required = true, name = "rybm") String rybm) {
		List<ClueCollectionDTO> list = this.iClueCollectionService.getCollectionByClueResultId(id, rybm);
		return CommonResponse.success(list);
	}

	@PostMapping("/addClueCollection")
	@ApiOperation(value = "新增线索集", notes = "新增线索集")
	public CommonResponse addClueCollection(@RequestBody JSONObject jSONObject) {
		return this.iClueCollectionService.addClueCollection(jSONObject);
	}

	@PostMapping("/addClueCollectionMap")
	@ApiOperation(value = "增加线索集线索关系", notes = "增加线索集线索关系")
	public CommonResponse addClueCollectionMap(@RequestBody JSONObject jSONObject) {
		return this.iClueCollectionMapService.addClueCollectionMap(jSONObject);
	}

	@PostMapping("/feedback")
	@ApiOperation(value = "成案反馈", notes = "成案反馈")
	public CommonResponse feedback(@RequestBody JSONObject jSONObject) {
		return this.iTaskDetailService.feedback(jSONObject) > 0 ? CommonResponse.success() : CommonResponse.failed(ResultEnum.CLUE_FEEDBACK_ERROR);
	}

	@PostMapping("/list/collection")
	@ApiOperation(value = "线索集列表分页查询", notes = "线索集列表分页查询")
	public CommonResponse listCollection(@RequestBody @Validated QueryClueCollectionListDTO queryClueCollectionListDTO) {
		return CommonResponse.success(this.iClueCollectionService.listCollection(queryClueCollectionListDTO));
	}

	@PostMapping("/list/collection/detail")
	@ApiOperation(value = "线索集列表-查看", notes = "线索集列表-查看")
	public CommonResponse collectionDetail(@RequestBody QueryClueDeatilDTO clueDeatilDTO) {
		return CommonResponse.success(this.iClueCollectionService.collectionDetail(clueDeatilDTO));
	}

	@DeleteMapping("/list/collection/{collectionId}")
	@ApiOperation(value = "线索集列表-删除", notes = "线索集列表-删除")
	public CommonResponse deleteCollection(@PathVariable(required = true, name = "collectionId") Integer collectionId) {
		return CommonResponse.success(this.iClueCollectionService.deleteCollection(collectionId));
	}

	@PostMapping("/list/collection/feedback")
	@ApiOperation(value = "线索集列表-成案反馈", notes = "线索集列表-成案反馈")
	public CommonResponse collectionFeedback(@RequestBody JSONObject jSONObject) {
		return CommonResponse.success(this.iClueCollectionService.collectionFeedback(jSONObject));
	}
	
	@GetMapping("/userdept/list")
	@ApiOperation("获取单位列表")
	public CommonResponse userdeptListDepartment(HttpServletRequest request) {
		JSONObject js = new JSONObject();
		Object user = StpUtil.getSession().get(AppConstants.LOGIN_USER_KEY);
		UapUserInfoVo uapUserInfoVo =(UapUserInfoVo) user;
		js.put("dwbm", uapUserInfoVo.getOrgCode());
		
		OuterResponse<List<OuterDeptNew>> outerResponse = sjztHttpInterface.depList(js);
		if(null == outerResponse || !outerResponse.getSuccess()) {
			js.put("dwbm", sjztDwbm);
			outerResponse = sjztHttpInterface.depList(js);
		}
		if(null == outerResponse || !outerResponse.getSuccess()) {
			return CommonResponse.failed("获取组织机构失败");
		}
		List<DepartmentVO> departmentVOList = Optional.ofNullable(outerResponse.getData()).map(Collection::stream)
		        .map(deptStream -> deptStream.map(dept -> converter.fromOuterNew(dept)).collect(Collectors.toList())).orElse(new ArrayList<>());
		logger.info("获取部门列表结束departmentVOList：{}", JSON.toJSONString(departmentVOList));
		// 组织树状结构
		Collection<DepartmentVO> tree = buildTree(departmentVOList);
		return CommonResponse.success(tree);
	}

	@GetMapping("/dept/list")
	@ApiOperation("获取单位列表")
	public CommonResponse listDepartment() {
		logger.info("获取单位列表");
		JSONObject js = new JSONObject();
		js.put("dwbm", sjztDwbm);
		OuterResponse<List<OuterDeptNew>> outerResponse = sjztHttpInterface.depList(js);
		List<DepartmentVO> departmentVOList = Optional.ofNullable(outerResponse.getData()).map(Collection::stream)
		        .map(deptStream -> deptStream.map(dept -> converter.fromOuterNew(dept)).collect(Collectors.toList())).orElse(new ArrayList<>());
		logger.info("获取部门列表结束departmentVOList：{}", JSON.toJSONString(departmentVOList));
		// 组织树状结构
		Collection<DepartmentVO> tree = buildTree(departmentVOList);
		return CommonResponse.success(tree);
	}

	private static Collection<DepartmentVO> buildTree(List<DepartmentVO> voList) {
		voList.forEach(vo -> {
			if (StringUtils.isBlank(vo.getSjjg())) {
				vo.setSjjg("0");
			}
		});
		Set<DepartmentVO> tree = new HashSet<>();
		Map<String, DepartmentVO> dwbmMap = voList.stream().collect(Collectors.toMap(e -> e.getDwbm(), e -> e));
		Map<String, List<DepartmentVO>> sjjgMap = voList.stream().collect(Collectors.groupingBy(DepartmentVO::getSjjg));
		// 找到所有顶级节点
		for (Map.Entry<String, List<DepartmentVO>> entry : sjjgMap.entrySet()) {
			String sjjgBM = entry.getKey();
			DepartmentVO sjjg = dwbmMap.get(sjjgBM);
			if (sjjg == null) {
				tree.addAll(entry.getValue());
			}
			else {
				DepartmentVO top = null;
				do {
					top = sjjg;
					sjjg = dwbmMap.get(sjjg.getSjjg());
				} while (sjjg != null);

				tree.add(top);
			}
		}
		// 从顶往下, 生成所有树
		findChildren(tree, sjjgMap);
		return tree;
	}

	private static void findChildren(Collection<DepartmentVO> parents, Map<String, List<DepartmentVO>> sjjgMap) {
		List<DepartmentVO> children = null;
		for (DepartmentVO parent : parents) {
			String sjjgBM = parent.getDwbm();
			children = sjjgMap.get(sjjgBM);
			if (CollectionUtils.isNotEmpty(children)) {
				children.sort(Comparator.comparing(DepartmentVO::getDwbm));
				parent.setChildren(children);
				findChildren(children, sjjgMap);
			}
		}
	}

	@GetMapping("/dept/org/{dwbm}")
	@ApiOperation("获取单位部门")
	public CommonResponse dwbmxx(@PathVariable(required = true, name = "dwbm") String dwbm) {
		logger.info("获取单位部门dwbm:{}", dwbm);
		OuterResponse<List<OuterDeptOrg>> outerResponse = sjztHttpInterface.dwbmxx(dwbm);
		logger.info("获取单位部门dwbm:{}结束", dwbm);
		return CommonResponse.success(outerResponse.getData());
	}

	@PostMapping("/dept/ry")
	@ApiOperation("获取单位人员")
	public CommonResponse dwryxx(@RequestBody QueryRyDTO queryRyDTO,HttpServletRequest request) {
		JSONObject js = new JSONObject();
		js.put("total", 0);
		js.put("records", new ArrayList<>());
		String zzdwbm = queryRyDTO.getZzdwbm();
		if (StringUtils.isEmpty(zzdwbm)) {
			Object user = StpUtil.getSession().get(AppConstants.LOGIN_USER_KEY);
			UapUserInfoVo uapUserInfoVo = (UapUserInfoVo)user;
			zzdwbm=uapUserInfoVo.getOrgCode();
		}
		logger.info("获取单位人员dwbm:{}", zzdwbm);
		OuterResponse<List<OuterDeptPerson>> outerResponse = sjztHttpInterface.dwryxx(zzdwbm);
		if(null == outerResponse || !outerResponse.getSuccess()) {
			zzdwbm=sjztDwbm;
			outerResponse = sjztHttpInterface.dwryxx(zzdwbm);
		}
		if(null == outerResponse || !outerResponse.getSuccess()) {
			js.put("total", 0);
			js.put("records", new ArrayList<>());
			return CommonResponse.success(js);
		}
		logger.info("获取单位人员dwbm:{}结束", zzdwbm);
		// 这里做个假分页 中台接口获取人员信息不分页
		Integer pageNo = queryRyDTO.getPageNo();
		Integer pageSize = queryRyDTO.getPageSize();
		List<OuterDeptPerson> list = outerResponse.getData();
		if (CollectionUtils.isEmpty(list)) {
			return CommonResponse.success(js);
		}
		if (StringUtils.isNotEmpty(queryRyDTO.getZzdwbm())) {
			list = list.stream().filter(v -> v.getDwbm().equals(queryRyDTO.getZzdwbm())).collect(Collectors.toList());
		}
		if (StringUtils.isNotEmpty(queryRyDTO.getDlbm())) {
			list = list.stream().filter(v -> v.getDlbm().contains(queryRyDTO.getDlbm())).collect(Collectors.toList());
		}
		if (StringUtils.isNotEmpty(queryRyDTO.getMc())) {
			list = list.stream().filter(v -> v.getMc().contains(queryRyDTO.getMc())).collect(Collectors.toList());
		}
		int start = 0;
		int end = 0;
		start = (pageNo - 1) * pageSize;
		end = start + pageSize;
		if (end > list.size()) {
			end = list.size();
		}
		if (CollectionUtils.isEmpty(list)) {
			js.put("total", 0);
			js.put("records", new ArrayList<>());
			return CommonResponse.success(js);
		}
		List<OuterDeptPerson> subList = list.subList(start, end);
		this.getClueNumByRyrm(subList);
		js.put("total", list.size());
		js.put("records", subList);
		return CommonResponse.success(js);
	}

	private void getClueNumByRyrm(List<OuterDeptPerson> subList) {
		for (OuterDeptPerson v : subList) {
			String rybm = v.getRybm();
			Long clueNum = iCluePushDetailService.getClueNumByRyrm(rybm);
			// 设置已推送线索数
			v.setPushedClueNum(clueNum);
			// 设置在办案件数
			OuterZbajParam outerZbajParam = new OuterZbajParam();
			outerZbajParam.setDwbm(v.getZzdwbm());
			outerZbajParam.setRybm(rybm);
			outerZbajParam.setCurrentPage(1);
			outerZbajParam.setPageSize(Integer.MAX_VALUE);
			OuterResponse<OuterZbajlb> outerResponse = sjztHttpInterface.zbajlb(outerZbajParam);
			if (null == outerResponse || !outerResponse.getSuccess()) {
				v.setDoingCaseNum(0);
				continue;
			}
			Set<String> bmsahSet =Optional.ofNullable(outerResponse.getData())
					.map(a -> a.getZbajlb())
					.map(a -> a.getRecords())
					.map(Collection::stream)
					.map(stream -> stream.map(OuterZbajlb.Record::getBmsah)).map(a -> a.collect(Collectors.toSet())).orElse(new HashSet<>());
			if (CollectionUtils.isEmpty(bmsahSet)) {
				v.setDoingCaseNum(0);
			}
			else {
				// 获取人员成案反馈的案件
				Set<String> set = iCluePushDetailService.getChenganBmsah(rybm);
				bmsahSet.retainAll(set);
				v.setDoingCaseNum(bmsahSet.size());
			}
		}
	}

	@PostMapping("/clue/push")
	@ApiOperation("线索推送")
	public CommonResponse push(@RequestBody PushClueDTO pushClueDTO) {
		logger.info("线索推送pushClueDTO:{}", JSON.toJSONString(pushClueDTO));
		int returnValue = iCluePushService.cluePush(pushClueDTO);
		logger.info("线索推送结束");
		return returnValue < 0 ? CommonResponse.failed("推送失败") : CommonResponse.success();
	}

	@PostMapping("/list/inquisitor/page")
	@ApiOperation(value = "线索管理分页查询(检查官个人)", notes = "线索管理分页查询(检查官个人)")
	public CommonResponse listInquisitor(@RequestBody com.iflytek.jcy.supervise.clue.dto.inquisitor.QueryClueDTO queryClueDTO) {
		return CommonResponse.success(this.iCluePushService.listInquisitor(queryClueDTO));
	}

	@PostMapping("/list/inquisitor/feedback")
	@ApiOperation(value = "线索管理分页查询(检查官个人)-成案反馈", notes = "线索管理分页查询(检查官个人)-成案反馈")
	public CommonResponse listInquisitorFeedback(@RequestBody JSONObject jSONObject) {
		return CommonResponse.success(this.iCluePushService.listInquisitorFeedback(jSONObject));
	}

	@PostMapping("/list/inquisitor/manage")
	@ApiOperation(value = "线索管理分页查询(检查官个人)-管理", notes = "线索管理分页查询(检查官个人)-管理")
	public CommonResponse listInquisitorManage(@RequestBody ManageDTO manageDTO) {
		return CommonResponse.success(this.iCluePushService.listInquisitorManage(manageDTO, true));
	}

	@PostMapping("/list/inquisitor/manage/feedback")
	@ApiOperation(value = "单个线索集（推送线索总览）-案件反馈", notes = "单个线索集（推送线索总览）-案件反馈")
	public CommonResponse listInquisitorManageFeedback(@RequestBody JSONObject jSONObject) {
		return CommonResponse.success(this.iCluePushDetailService.listInquisitorManageFeedback(jSONObject));
	}

	@PostMapping("/list/inquisitor/queryInquisitorCollection/{rybm}")
	@ApiOperation(value = "检察官个人-查询线索集", notes = "检察官个人-查询线索集")
	public CommonResponse queryInquisitorCollection(@PathVariable(required = true, name = "rybm") String rybm) {
		return CommonResponse.success(this.iCluePushService.queryInquisitorCollection(rybm));
	}

	@PostMapping("/list/inquisitor/addInquisitorCollection")
	@ApiOperation(value = "检察官个人-新建线索集", notes = "检察官个人-新建线索集")
	public CommonResponse addInquisitorCollection(@RequestBody JSONObject jsonObject) {
		return this.iCluePushService.addInquisitorCollection(jsonObject);
	}

	@PostMapping("/list/inquisitor/addMap")
	@ApiOperation(value = "检察官个人-线索集增加线索", notes = "检察官个人-线索集增加线索")
	public CommonResponse addMap(@RequestBody InquisitorAddMapDTO inquisitorAddMapDTO) {
		return this.iCluePushService.addMap(inquisitorAddMapDTO);
	}

	@PostMapping("/list/inquisitor/setWeight/{pushDetailId}/{weight}")
	@ApiOperation(value = "检察官个人-设置权重", notes = "检察官个人-设置权重")
	public CommonResponse setInquisitorWeight(@PathVariable(required = true, name = "pushDetailId") Integer pushDetailId, @PathVariable(required = true, name = "weight") Integer weight) {
		logger.info("setInquisitorWeight pushDetailId:{},weight:{}", pushDetailId, weight);
		return this.iCluePushService.setInquisitorWeight(pushDetailId, weight) > 0 ? CommonResponse.success() : CommonResponse.failed("设置权重失败");
	}

	@GetMapping("/getPonits/{taskId}")
	@ApiOperation(value = "根据taskId获取所有监督点", notes = "根据taskId获取所有监督点")
	public CommonResponse getPonits(@PathVariable(required = true, name = "taskId") Integer taskId) {
		logger.info("getPonits taskId:{}", taskId);
		return CommonResponse.success(this.iClueService.getPointsByTaskId(taskId));
	}

	@PostMapping("/info")
	@ApiOperation(value = "查看(管理员)", notes = "查看(管理员)")
	public CommonResponse info(@RequestBody QueryClueDetailDTO queryClueDetailDTO) {
		return CommonResponse.success(mongoService.info(queryClueDetailDTO));
	}

	@PostMapping("/inquisitorInfo")
	@ApiOperation(value = "查看(检察官)", notes = "查看(检察官)")
	public CommonResponse inquisitorInfo(@RequestBody ManageDTO manageDTO) {
		ManageDTO newManageDTO = new ManageDTO();
		newManageDTO.setPageNo(1);
		newManageDTO.setPageSize(Integer.MAX_VALUE);
		newManageDTO.setPushId(manageDTO.getPushId());
		newManageDTO.setPointId(manageDTO.getPointId());
		IPage<ManageTaskDetailDTO> page = this.iCluePushService.listInquisitorManage(newManageDTO, false);
		List<ManageTaskDetailDTO> list = page.getRecords();
		if (CollectionUtils.isEmpty(list)) {
			return CommonResponse.success(new MongoPageResult());
		}
		// 根据多个Id pointId获取Mongo数据 这里是夸任务查看
		List<Integer> ids = list.stream().map(ManageTaskDetailDTO::getId).collect(Collectors.toList());
		QueryClueDetailDTO queryClueDetailDTO = new QueryClueDetailDTO(manageDTO.getPageNo(), manageDTO.getPageSize(), manageDTO.getPointId(), ids);
		return CommonResponse.success(mongoService.info(queryClueDetailDTO));
	}

	@GetMapping("/info/{id}")
	@ApiOperation(value = "详情", notes = "详情")
	public CommonResponse info(@PathVariable(required = true, name = "id") Integer id) {
		return CommonResponse.success(mongoService.info(id));
	}

	@ApiOperation(value = "线索结果列表（管理员）(左上角下载)和监督点查看里面的下载", notes = "线索结果列表（管理员）(左上角下载)和查看里面的下载")
	@RequestMapping(value = "/exportClue/{clueId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public void export1(@PathVariable(required = true, name = "clueId") Integer clueId, HttpServletResponse response) throws Exception {
		long start = System.currentTimeMillis();
		logger.debug("线索结果列表（管理员）下载 start clueId:{}", clueId);
		this.iClueService.export1(clueId, response);
		logger.debug("线索结果列表（管理员）下载 end！clueId:{}耗时：{}ms.", clueId, System.currentTimeMillis() - start);
	}

	@ApiOperation(value = "详情下载", notes = "详情下载")
	@RequestMapping(value = "/exportDetail/{id}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public void exportDetail(@PathVariable(required = true, name = "id") Integer id, HttpServletResponse response) throws Exception {
		long start = System.currentTimeMillis();
		logger.debug("详情下载 start id:{}", id);
		this.iClueService.exportDetail(id, response);
		logger.debug("详情下载 end！耗时：{}ms. id:{}", System.currentTimeMillis() - start, id);
	}

	@ApiOperation(value = "查看下载", notes = "查看下载")
	@RequestMapping(value = "/exportInfo/{taskLogId}/{pointId}", method = RequestMethod.GET, produces = "application/json;charset=UTF-8")
	public void exportInfo(@PathVariable(required = true, name = "taskLogId") Integer taskLogId, @PathVariable(required = true, name = "pointId") Integer pointId, HttpServletResponse response)
	        throws Exception {
		long start = System.currentTimeMillis();
		logger.debug("单条线索详情下载 start taskLogId:{} pointId:{}", taskLogId, pointId);
		this.iClueService.exportInfo(taskLogId, pointId, response);
		logger.debug("单条线索详情下载 end！耗时：{}ms. taskLogId:{} pointId:{}", System.currentTimeMillis() - start, taskLogId, pointId);
	}

	@ApiOperation(value = "线索集下载", notes = "线索集下载")
	@RequestMapping(value = "/exportCollection", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public void exportCollection(@RequestBody QueryClueDeatilDTO clueDeatilDTO, HttpServletResponse response) throws Exception {
		long start = System.currentTimeMillis();
		logger.debug("线索集下载 start keyword:{}collectionId:{}", clueDeatilDTO.getKeyword(), clueDeatilDTO.getCollectionId());
		this.iClueService.exportCollection(clueDeatilDTO, response);
		logger.debug("线索集下载 end！耗时：{}ms.keyword:{}collectionId:{}", System.currentTimeMillis() - start, clueDeatilDTO.getKeyword(), clueDeatilDTO.getCollectionId());
	}

	@ApiOperation(value = "线索总览下载-检察官", notes = "线索集下载")
	@RequestMapping(value = "/exportOverview", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public void exportOverview(@RequestBody ManageDTO manageDTO, HttpServletResponse response) throws Exception {
		long start = System.currentTimeMillis();
		ManageDTO newManageDTO = new ManageDTO(1, Integer.MAX_VALUE, manageDTO.getPushId(), manageDTO.getKeyword());
		logger.debug("线索总览下载 start keyword:{}pushId:{}", manageDTO.getKeyword(), manageDTO.getPushId());
		this.iClueService.exportOverview(newManageDTO, response);
		logger.debug("线索总览下载 end！耗时：{}ms.keyword:{}pushId:{}", System.currentTimeMillis() - start, manageDTO.getKeyword(), manageDTO.getPushId());
	}

	@GetMapping("/check/{modelId}")
	@ApiOperation(value = "校验模型是否关联过任务", notes = "校验模型是否关联过任务")
	public CommonResponse check(@PathVariable(required = true, name = "modelId") Integer modelId) {
		return iClueService.check(modelId);
	}

	@GetMapping("/getPonitsByPushId/{pushId}")
	@ApiOperation(value = "根据推送id获取所有监督点", notes = "根据推送id获取所有监督点")
	public CommonResponse getPonitsByPushId(@PathVariable(required = true, name = "pushId") Integer pushId) {
		logger.info("getPonitsByPushId pushId:{}", pushId);
		return CommonResponse.success(this.iClueService.getPonitsByPushId(pushId));
	}

	@ApiOperation(value = "查看下载-检察官", notes = "查看下载-检察官")
	@RequestMapping(value = "/exportChakan", method = RequestMethod.POST, produces = "application/json;charset=UTF-8")
	public void exportChakan(@RequestBody ManageDTO manageDTO, HttpServletResponse response) throws Exception {
		long start = System.currentTimeMillis();
		manageDTO.setPageNo(1);
		manageDTO.setPageSize(Integer.MAX_VALUE);
		logger.debug("线索总览下载 start keyword:{}pushId:{}", manageDTO.getKeyword(), manageDTO.getPushId());
		this.iClueService.exportChakan(manageDTO, response);
		logger.debug("线索总览下载 end！耗时：{}ms.keyword:{}pushId:{}", System.currentTimeMillis() - start, manageDTO.getKeyword(), manageDTO.getPushId());
	}
}
